/*
 * @lc app=leetcode.cn id=169 lang=javascript
 *
 * [169] 多数元素
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function (nums) {
  let winner = nums[0];
  let cnt = 1;
  for (let i = 1; i < nums.length; i++) {
    if (winner === nums[i]) cnt++;
    else if (cnt === 0) {
      winner = nums[i];
      cnt++;
    } else {
      cnt--;
    }
  }
  return winner;
};
// @lc code=end
